<template>
    <div class="wrapper">
        <!-- 页面头部部分 -->
        <div class="header">
            <div class="logo">停车收费系统</div>
            <!-- 水平一级菜单 -->
            <div class="menu-bar">
                <el-menu
                    mode="horizontal"
                    text-color="#c0d0e8"
                    active-text-color="#2D4FA2"
                    :default-active="toIndex"
                    @select="handleSelect"
                >
                    <el-menu-item v-for="(item, index) in itemList" :index="item.path" :key="index">
                        <span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </el-menu>
            </div>

            <div class="header-right">
                <div class="hearder-site">大兴停车场</div>
                <div class="reset-site">空余车位：2456/8888</div>
                <div class="header-user-con">
                    <!-- 用户头像 -->
                    <div class="user-avator">
                        <img src="@/assets/img/img.jpg" />
                    </div>
                    <!-- 用户名下拉菜单 -->
                    <el-dropdown class="user-name" trigger="click" @command="handleCommand">
                        <span class="el-dropdown-link"> {{ username }} <i class="el-icon-caret-bottom"></i></span>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item disabled>修改密码</el-dropdown-item>
                            <el-dropdown-item command="loginout">退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </div>
            </div>
        </div>

        <!-- 页面左侧二级菜单栏，和主体内容区域部分 -->
        <div>
            <router-view></router-view>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            itemList: [
                // 水平一级菜单栏的菜单
                { path: '/Home', title: '首页' },
                { path: '/park', title: '基础配置' },
                {path:'/user',title:'用户管理'}
            ]
        };
    },
    computed: {
        username() {
            return localStorage.getItem('ms_username') || '';
        },
        toIndex() {
            // 根据路径绑定到对应的一级菜单，防止页面刷新重新跳回第一个
            return '/' + this.$route.path.split('/')[1];
        }
    },
    created() {},
    methods: {
        handleSelect(path) {
            // 切换菜单栏
            this.$router.push({
                path: path
            });
        },
        handleCommand(command) {
            // 用户名下拉菜单选择事件
            if (command == 'loginout') {
                localStorage.removeItem('ms_username');
                this.$router.push({
                    path: '/Login'
                });
            }
        }
    }
};
</script>

<style scoped>
.wrapper {
  width: 100%;
  height: 100%;
  background: #EEEEEE;
}
.header {
  background: #2D4FA2;
  position: relative;
  width: 100%;
  height: 52px;
  display:flex;
  align-items: center;
  position: fixed;
  left: 0;
  right: 0;
  z-index: 100;
}
.header .logo {
  font-size: 24px;
  color: #FFFFFF;
  line-height: 34px;
  margin-left: 100px;
}
/* --------------- 用户头像区域的样式 ---------------- */

.header-right {
  display: flex;
  align-items: center;
  line-height: 52px;
  color: #c0d0e8;
  padding-right: 36px;
}
.hearder-site{
  background: url(../../assets/img/park-site.png) no-repeat left center;
  margin-right: 22px;
  background-size:11px 13px ;
  padding-left: 15px;
}
.reset-site{
  margin-right: 54px;
}
.header-user-con {
  display: flex;
  align-items: center;
  justify-content: center;

}
.menu-bar{
  flex: 1;
}
.user-avator {
  margin-left: 20px;
}
.user-avator img {
  display: block;
  width: 24px;
  height: 24px;
  border-radius: 50%;
}
.user-name {
  margin-left: 10px;
}
.el-dropdown-link {
  cursor: pointer;
  color:#fff;
}
.el-dropdown-menu__item {
  text-align: center;
}
/* --------------- 水平一级菜单栏的样式--------------------- */
.el-menu.el-menu--horizontal {
  border-bottom: none !important;
  float: left;
  margin-left: 50px;
  background: transparent;
}
.el-menu--horizontal > .el-menu-item.is-active {
  font-weight: bold;
  background: url(../../assets/img/menu-bg.png) no-repeat;
  background-size: 150px 48px;
  border-bottom: none;
  background-position-y: 5px;
}
.el-menu--horizontal > .el-menu-item {
  font-size: 16px;
  height: 52px;
  width: 150px;
  margin-right:52px ;
  padding:0;
  text-align: center;
}
 .el-menu--horizontal .el-menu-item:not(.is-active):hover{
    background: #2D4FA2;
 }
</style>
